package com.woniu.service.Impl.homePage;

import com.woniu.dao.homePage.MyAppDao;
import com.woniu.entity.Comment;
import com.woniu.entity.Orders;
import com.woniu.entity.OrdersDetails;
import com.woniu.service.homePage.IMyAppService;
import com.woniu.util.ResData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author 陈乙嘉
 * @data 2023/3/14 17:12
 */
@Service
public class MyAppServiceImpl implements IMyAppService {

    @Autowired(required = false)
    private MyAppDao myAppDao;

    @Override
    public ResData<?> getMyOrdersAndOrderDetails(Orders orders) {
        List<Orders> myOrders = myAppDao.findMyOrders(orders);
        for(Orders o: myOrders){
            List<OrdersDetails> orderDetails = myAppDao.findOrderDetailsByOrderId(o.getId());
            o.setOrdersDetails(orderDetails);
        }

        return new ResData<>().ok(myOrders);

    }

    @Override
    public ResData<?> userUpdateOrderStatus(Orders orders) {
        myAppDao.userUpdateOrderStatus(orders);
        return new ResData<>().ok();
    }

    @Override
    public ResData<?> insertComments(Comment comment) {
        myAppDao.insertComments(comment);
        return new ResData<>().ok();
    }


    //根据手机号和状态为3查询配送员id
    @Override
    public ResData<?> findDispatcherIdByPhoneAndStatus(String phone,String orderId) {
        Long dispatcherIdByPhoneAndStatus = myAppDao.findDispatcherIdByPhoneAndStatus(phone,orderId);
        return new ResData<>().ok(dispatcherIdByPhoneAndStatus);
    }


}
